package com.lyshop.jinxiang.activitys;

import android.view.View;
import android.widget.TextView;

import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import com.lyshop.jinxiang.R;
import com.lyshop.jinxiang.adapters.RetailTicketAdapter;
import com.lyshop.jinxiang.application.MyApplication;
import com.lyshop.jinxiang.base.BaseActivity;
import com.lyshop.jinxiang.bean.RetailTicketBean;
import com.lyshop.jinxiang.net.ActionCallbackListener;
import com.lyshop.jinxiang.utils.ToastUtil;

import java.util.ArrayList;
import java.util.List;

public class RetailTicketActivity extends BaseActivity {

    private RecyclerView retail_ticket_rv;
    private List list = new ArrayList<>();
    private RetailTicketAdapter adapter;
    private TextView not_data_tv;

    @Override
    protected int setContentView() {
        return R.layout.activity_retail_ticket;
    }
    @Override
    protected void findViews() {
        retail_ticket_rv =$(R.id._reatil_ticket_history_rv);
        not_data_tv = $(R.id.not_data_tv);
        retail_ticket_rv.setLayoutManager(new LinearLayoutManager(mContext));
        adapter = new RetailTicketAdapter(mContext,list);
        retail_ticket_rv.setAdapter(adapter);
        getListData();
    }

    @Override
    protected void setListeners() {

    }
    private void getListData(){
        mAppAction =  MyApplication.getApplication().getAppAction();
        mAppAction.getRetailTicketList(new ActionCallbackListener<List<RetailTicketBean>>() {
            @Override
            public void onSuccess(List<RetailTicketBean> data) {
                    list.clear();
                    list.addAll(data);
                    if(list.size()>0){
                        not_data_tv.setVisibility(View.GONE);
                        retail_ticket_rv.setVisibility(View.VISIBLE);
                    }else{
                        not_data_tv.setVisibility(View.VISIBLE);
                        retail_ticket_rv.setVisibility(View.GONE);
                    }
                    adapter.notifyDataSetChanged();
            }
            @Override
            public void onFailure(String errorCode, String message) {
                ToastUtil.showToast(mContext,message);
            }
        });
    }
}
